<?php

// +----------------------------------------------------------------------
// | ADM Software [ 我宁可 为做过的事而后悔，也不想 因为没尝试而后悔。 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2014 扬州安蝶梦电子商务有限公司 All rights reserved.
// +----------------------------------------------------------------------
// | Author: 曹梦龙 <138888611@qq.com> <http://www.andiemeng.com>
// +----------------------------------------------------------------------

namespace Org\GrLBS;

//提供从地址到经纬度坐标或者从经纬度坐标到地址的转换服务
class GeoCoder {

    public function Geocoding($address,$city) {
        $point = new \Org\BMap\Point();
        $post_string = "ak=W7fSw2UYZWEZsT8sr0jH6OuF&output=json&address=".urlencode($address)."&city=".$city;
        $result= $this->https_request("http://api.map.baidu.com/geocoder/v2/",$post_string);
        //dump(json_decode($result));
        return json_decode($result);
    }

     //http工具
    function https_request($url, $data = null) {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        if (!empty($data)) {
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }

}
